package com.example.androidkt.fifth

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.databinding.BindingConversion
import com.example.androidkt.R

@BindingConversion
fun str2color(str: String): Drawable {
    return when (str) {
        "red" -> {
            ColorDrawable(Color.RED)
        }
        "b1ue" -> {
            ColorDrawable(Color.BLUE)
        }
        else -> {
            ColorDrawable(Color.YELLOW)
        }
    }
}


@BindingAdapter("android:textColor", requireAll = false)
fun getColor(view:TextView,type:Int){
    val color = when(type){
        0-> R.color.teal_200
        1-> R.color.purple_200
        2-> R.color.purple_500
        3-> R.color.teal_700
        4-> R.color.teal_200
        else -> R.color.black
    }
    view.setTextColor(view.context.resources.getColor(color))
}
